# import pprint

classes = [
    {'name': 'n_1', 'age': 24, 'grade': 'A'},
    {'name': 'n_2', 'age': 23, 'grade': 'B'},
    {'name': 'n_3', 'age': 28, 'grade': 'A'},
    {'name': 'n_4', 'age': 24, 'grade': 'A'},
    {'name': 'n_5', 'age': 25, 'grade': 'C'},
    {'name': 'n_6', 'age': 21, 'grade': 'D'},
    {'name': 'n_7', 'age': 27, 'grade': 'A'}    
]

#以grade 排序
classes.sort(key= lambda x: x['grade'])
print(classes)
for iterm in classes:
    print(iterm)

#筛选grade=A的同学
grade_A = filter(lambda x: True if x['grade'] == 'A' else False, classes )
a = list(grade_A)
print(a)
for iterm in a:
    print(iterm)

#为同学年龄+1
def age(item):
    item['age'] = item['age'] + 1
    return item

new_class = map(age, classes)
print(list(new_class))



#[0,1,1,2,3,5,f(n)]

# def f(n):
#     return l[n-1]+l[n-2]
    # if n < 2:
    #     return l

    # f(n) = f(n-1) + f(n-2)
    # return f(n)

    # l.append(f(n))

# [0,1,1,2,3,5,8]


feibo = []
def feibo_item(n):
        if n == 1 :
            return 1
        elif n==0 :
            return 0
        return feibo_item(n-1) + feibo_item(n-2)

print(feibo)

def feibo_list(n):
    for i in range(n):
        feibo.append(feibo_item(i))
feibo_list(5)
print(feibo)